home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 5
/
Gekikoh Dennoh Club Vol. 5 (Japan).7z
/
Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin
/
internet
/
tcppack
/
tcppackb.lzh
/
src
/
libnetwork
/
sock.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-10
|
2KB
|
98 lines
/*
* sock.c
*
* Copyright (C) 1994 First Class Technology.
*/
#include<stdio.h>
#include<stdlib.h>
#include<stddef.h>
#include<string.h>
#include"tcpipdrv.h"
#include"network.h"
_ti_func search_ti_entry (void);
#define NOTUSED (0)
#define SOCKBASE 128
#define DEFNSOCK 32
typedef struct usock
{
int refcnt;
char noblock;
char type;
int rdysock;
void *p;
char *name;
int namelen;
char *peername;
int peernamelen;
char errcodes[4]; /* Protocol-specific error codes */
void *obuf; /* Output buffer */
void *ibuf; /* Input buffer */
char eol[3]; /* Text mode end-of-line sequence, if any */
int flag; /* Mode flags, defined in socket.h */
int flush; /* Character to trigger flush, if any */
int event;
} usock;
long *
get_sock_array (int *_n)
{
struct usock *p;
_ti_func func = search_ti_entry ();
if (func)
{
int n, i;
usock *q;
long *dst;
p = (usock *)func (_TI_sock_top, NULL);
n = 0;
for (i = n = 0, q = p; i < DEFNSOCK; i++, q++)
{
if (q->type != NOTUSED)
n++;
}
if (n)
{
long *x;
dst = (long *)malloc (n * sizeof (long));
if (!dst)
return NULL;
x = dst;
for (i = 0, q = p; i < DEFNSOCK; i++, q++)
{
if (q->type != NOTUSED)
{
*x++ = i + SOCKBASE;
}
}
*_n = n;
return dst;
}
}
return NULL;
}
/************************************************
* *
************************************************/
char *
ntoa_sock (int sock, int type, char *p, int mode)
{
_ti_func func = search_ti_entry ();
long args[4];
if (func)
{
args[0] = sock;
args[1] = type;
args[2] = (long)p;
args[3] = mode;
return (char *)func (_TI_ntoa_sock, args);
}
return NULL;
}